package com.train.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.train.user.domain.SysNotification;
import com.train.user.service.SysNotificationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.train.common.annotation.Log;
import com.train.common.core.controller.BaseController;
import com.train.common.core.domain.AjaxResult;
import com.train.common.enums.BusinessType;
import com.train.common.utils.poi.ExcelUtil;
import com.train.common.core.page.TableDataInfo;

/**
 * 系统通知Controller
 * 
 * @author train
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/notification")
public class SysNotificationController extends BaseController
{
    @Autowired
    private SysNotificationService sysNotificationService;

    /**
     * 查询系统通知列表
     */
    @PreAuthorize("@ss.hasPermi('category:notification:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysNotification sysNotification)
    {
        startPage();
        List<SysNotification> list = sysNotificationService.selectSysNotificationList(sysNotification);
        return getDataTable(list);
    }

    /**
     * 导出系统通知列表
     */
    @PreAuthorize("@ss.hasPermi('category:notification:export')")
    @Log(title = "系统通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysNotification sysNotification)
    {
        List<SysNotification> list = sysNotificationService.selectSysNotificationList(sysNotification);
        ExcelUtil<SysNotification> util = new ExcelUtil<SysNotification>(SysNotification.class);
        util.exportExcel(response, list, "系统通知数据");
    }

    /**
     * 获取系统通知详细信息
     */
    @PreAuthorize("@ss.hasPermi('category:notification:query')")
    @GetMapping(value = "/{notificationId}")
    public AjaxResult getInfo(@PathVariable("notificationId") Long notificationId)
    {
        return success(sysNotificationService.selectSysNotificationByNotificationId(notificationId));
    }

    /**
     * 新增系统通知
     */
    @PreAuthorize("@ss.hasPermi('category:notification:add')")
    @Log(title = "系统通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysNotification sysNotification)
    {
        return toAjax(sysNotificationService.insertSysNotification(sysNotification));
    }

    /**
     * 修改系统通知
     */
    @PreAuthorize("@ss.hasPermi('category:notification:edit')")
    @Log(title = "系统通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysNotification sysNotification)
    {
        return toAjax(sysNotificationService.updateSysNotification(sysNotification));
    }

    /**
     * 删除系统通知
     */
    @PreAuthorize("@ss.hasPermi('category:notification:remove')")
    @Log(title = "系统通知", businessType = BusinessType.DELETE)
	@DeleteMapping("/{notificationIds}")
    public AjaxResult remove(@PathVariable Long[] notificationIds)
    {
        return toAjax(sysNotificationService.deleteSysNotificationByNotificationIds(notificationIds));
    }
}
